#include <iostream>
#include <cstdio>
#include <cerrno>
#include <cstring>
#include <cassert>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "comm.hpp"

int main(){
    //打开管道文件
    int wfd = open(fifoName.c_str(), O_WRONLY);
    if(wfd < 0){
        cerr << errno << ": " << strerror(errno) << endl;
        return 1;
    }

    //进行常规通信
    char buffer[NUM];
    while(true){
        cout << "send massage : " << endl;
        char *msg = fgets(buffer, sizeof(buffer), stdin);
        assert(msg);
        (void)msg;
        
        //将发送的回车\n去掉
        buffer[strlen(buffer) - 1] = 0;

        ssize_t n = write(wfd, buffer, strlen(buffer));
        assert(n >= 0);
        (void)n;
    }

    close(wfd);
    unlink(fifoName.c_str());
}